<?php //if(!empty($category->description)): ?>
<!--<div class="row">-->
<!--    <div class="span9">--><?php //echo $category->description; ?><!--</div>-->
<!--</div>-->
<?php //endif; ?>

<div class="features_items"><!--features_items-->
    <div class="category-tab">
        <ul class="nav nav-tabs head">
            <li><a class="head"><?php echo $page_title ?></a></li>
        </ul>
    </div>
    <div class="wrap_item">
        <?php
        $cols = 4;
        if (isset($category)):?>
            <?php if (isset($this->categories[$category->id]) && count($this->categories[$category->id]) > 0):
                $cols = 3; ?>
                <div class="span3">
                    <ul class="nav nav-list well">
                        <li class="nav-header">
                            <?php echo lang('subcategories'); ?>
                        </li>

                        <?php foreach ($this->categories[$category->id] as $subcategory): ?>
                            <li>
                                <a href="<?php echo site_url(implode('/', $base_url) . '/' . $subcategory->slug); ?>"><?php echo $subcategory->name; ?></a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endif; ?>
        <?php endif; ?>
        <?php if (count($products) == 0): ?>
            <h2 style="margin:50px 0px; text-align:center;">
                <?php echo lang('no_products'); ?>
            </h2>
        <?php elseif (count($products) > 0): ?>
            <div class="col-sm-12" style="margin-top:10px; margin-bottom:15px">
                Hiển thị theo
                <select id="sort_products" class="sel_sort" onchange="window.location='<?php echo site_url(uri_string()); ?>/'+$(this).val();">
                    <option value=''><?php echo lang('default'); ?></option>
                    <option<?php echo (!empty($_GET['by']) && $_GET['by'] == 'name/asc') ? ' selected="selected"' : ''; ?>
                        value="?by=name/asc"><?php echo lang('sort_by_name_asc'); ?></option>
                    <option<?php echo (!empty($_GET['by']) && $_GET['by'] == 'name/desc') ? ' selected="selected"' : ''; ?>
                        value="?by=name/desc"><?php echo lang('sort_by_name_desc'); ?></option>
                    <option<?php echo (!empty($_GET['by']) && $_GET['by'] == 'price/asc') ? ' selected="selected"' : ''; ?>
                        value="?by=price/asc"><?php echo lang('sort_by_price_asc'); ?></option>
                    <option<?php echo (!empty($_GET['by']) && $_GET['by'] == 'price/desc') ? ' selected="selected"' : ''; ?>
                        value="?by=price/desc"><?php echo lang('sort_by_price_desc'); ?></option>
                </select>
            </div>
            <?php foreach ($products as $product):?>
                <div class="col-sm-3">
                    <?php
                    $photo = theme_img('no_picture.png', lang('no_image_available'));
                    $product->images = array_values($product->images);

                    if (!empty($product->images[0])) {
                        $primary = $product->images[0];
                        foreach ($product->images as $photo) {
                            if (isset($photo->primary)) {
                                $primary = $photo;
                            }
                        }

                        $photo = '<img src="' . base_url('uploads/images/thumbnails/' . $primary->filename) . '" alt="' . $product->seo_title . '"/>';
                    }
                    ?>
                    <div class="product-image-wrapper">
                        <div class="single-products">
                            <div class="productinfo text-center">
                                <div class="wrap_image_detail">
                                    <?php echo $photo; ?>
                                </div>
                                <div class="split_item_product_wrapper"></div>
                                <?php if ((bool)$product->track_stock && $product->quantity < 1 && config_item('inventory_enabled')) { ?>
                                    <div class="stock_msg"><?php echo lang('out_of_stock'); ?></div>
                                <?php } else { ?>
                                    <?php if ($product->saleprice > 0): ?>
                                        <h2 class="price-slash_before_sale"><?php echo format_currency($product->price); ?></h2>
                                        <h2 class="price-slash_after_sale"><?php echo format_currency($product->saleprice); ?></h2>
                                    <?php else: ?>
                                        <h2 class="price-slash"><?php echo format_currency($product->price); ?></h2>
                                    <?php endif; ?>
                                <?php } ?>
                                <div class="split_item_product_wrapper"></div>
                                <p><?php echo $product->name;?></p>
                            </div>
                            <?php if ($product->saleprice > 0): ?>
                                <img src="<?php echo base_url('assets/img/sale.png') ?>" class="new" alt="">
                            <?php endif; ?>
                        </div>
                        <div class="choose">
                            <ul class="nav nav-justified">
                                <li>
                                    <a href="<?php echo site_url(implode('/', $base_url) . '/' . $product->slug); ?>"
                                       class="btn btn-default add-to-cart-small"><i class="fa fa-shopping-cart"></i><?php echo lang('prd_detail')?></a>
                                </li>
                            </ul>
                        </div>
                    </div>
<!--                    --><?php //if ($product->excerpt != ''): ?>
<!--                        <div class="excerpt">--><?php //echo $product->excerpt; ?><!--</div>-->
<!--                    --><?php //endif; ?>
                </div>
            <?php endforeach; ?>
            <div class="col-sm-12" style="margin-top:10px; margin-bottom:15px">
                <?php echo $this->pagination->create_links(); ?>&nbsp;
            </div>
        <?php endif; ?>
    </div>
</div>